#! /usr/bin/env python
# -*- coding: utf-8 -*-
#shortpath.py



import os.path



def shortpath(longpath):
    # defines separator, path and creates shortpath list
    separator = os.path.sep
    path = longpath
    shortpath = []
    
    # constant part of the path 
    # in '/etc/firefox/profile' it would be '/profile'
    # appends first case of shortpath ex. '/profile'
    x = path.rpartition(separator)
    const = x[1] + x[2]
    shortpath.append(const)
    
    # variable part of the path 
    # in '/etc/firefox/profile' it would be '/etc/firefox'
    # appends second case of shortpath ex. '/.../profile'
    y = path.partition(separator)
    base = y[0] + y[1]
    path = y[2]
    shortpath.append('{0}...{1}'.format(base,const))
     
    # calculates every possible variable part
    # appends each possibility
    # finally appends the longpath
    while base != longpath:
        z = path.partition(separator)
        base = base + z[0] + z[1]
        path = z[2]
        if '{0}{1}'.format(base,const[1:]) == longpath:
            shortpath.append(longpath)
        elif const in base:
            pass
        else:
            shortpath.append('{0}...{1}'.format(base,const))
    
    shortpath.reverse()
    return shortpath

if __name__ == '__main__':
    longpath = os.path.abspath(os.curdir)
    shortpath = shortpath(longpath)
    print shortpath
